// import {renderEngin} from "./function/renderEnginforIndex";

export function addMassMark(map, data_content, that) {
    //加载PointSimplifier，loadUI的路径参数为模块名中 'ui/' 之后的部分
    AMapUI.loadUI(['misc/PointSimplifier'], function (PointSimplifier) {

        if (!PointSimplifier.supportCanvas) {
            return;
        }

        //启动页面
        initPage(PointSimplifier, map, data_content, that);
    });
}

function initPage(PointSimplifier, map, data_content, that) {
    //创建组件实例
    var pointSimplifierIns = new PointSimplifier({
        map: map, //关联的map
        getPosition: function (dataItem) {
            //返回数据项的经纬度，AMap.LngLat实例或者经纬度数组
            return dataItem.lnglat;
        },
        getHoverTitle: function (dataItem) {
            //返回数据项的Title信息，鼠标hover时显示
            return `${dataItem.monitor} ${dataItem.phonenumber}`;
        },
        renderOptions: {
            //点的样式
            drawPositionPoint: false,
            pointStyle: {
                fillStyle: 'red',
                content: PointSimplifier.Render.Canvas.getImageContent(
                    require("../../../assets/image/4.png"),
                    function onload() {
                        pointSimplifierIns.renderLater();
                    },
                    function onerror(e) {
                        console.error(e)
                    }),
                width: 25,
                height: 25,
            },
            pointHoverStyle: {
                content: "none",
                width: 15,
                height: 15,
            },
            hoverTitleStyle: {
                position: "top",
                ClassName: "hovertitle"
            },
            autoSetFitView: false
        },
        zIndex: 77,
        autoSetFitView: false
    });

    //设置数据源，data需要是一个数组
    pointSimplifierIns.setData(data_content);

    //监听事件
    pointSimplifierIns.on('pointClick', function (e, record) {
        // let TowerId = record.data.TowerId;
        that.$emit("clickSpot", record.data);
        // that.$router.push({ name: "tower", query: { index: TowerId } });
    });
    map.setCenter(data_content[0].lnglat);
    return pointSimplifierIns
}

export function updateMassmark(map, data_content, pointSimplifierIns) {
    pointSimplifierIns.setData(data_content);

    // map.setCenter(data_content[0].lnglat);
}